<?php 
set_time_limit(0);
ini_set("memory_limit", "12M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
//sort name
function CompareNameASC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] < $b[0]) ? -1 : 1;
}
function CompareNameDESC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] > $b[0]) ? -1 : 1;
}
// sort total
function CompareTotalASC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] < $b[1]) ? -1 : 1;
}
function CompareTotalDESC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] > $b[1]) ? -1 : 1;
}
// sort unrecognize
function CompareUnrecognizeASC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] < $b[2]) ? -1 : 1;
}
function CompareUnrecognizeDESC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] > $b[2]) ? -1 : 1;
}
//sort fail
function CompareFailASC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] < $b[3]) ? -1 : 1;
}
function CompareFailDESC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] > $b[3]) ? -1 : 1;
}
//sort ok
function CompareOkASC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] < $b[4]) ? -1 : 1;
}
function CompareOkDESC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] > $b[4]) ? -1 : 1;
}
//sort Persent
function ComparePersentASC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] < $b[5]) ? -1 : 1;
}
function ComparePersentDESC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] > $b[5]) ? -1 : 1;
}
if (isset($_SESSION['s_recognizes']) and is_array($_SESSION['s_recognizes']) and isset($_REQUEST['flag'])) {
	
	$mylist = $_SESSION['s_recognizes'];
	if($_REQUEST['flag']=='20'){
		usort($mylist, 'CompareNameASC');
	}elseif($_REQUEST['flag']=='21'){
		usort($mylist, 'CompareNameDESC');
	}
	elseif($_REQUEST['flag']=='30'){
		usort($mylist, 'CompareTotalASC');
	}elseif($_REQUEST['flag']=='31'){
		usort($mylist, 'CompareTotalDESC');
	}
	elseif($_REQUEST['flag']=='40'){
		usort($mylist, 'CompareUnrecognizeASC');
	}elseif($_REQUEST['flag']=='41'){
		usort($mylist, 'CompareUnrecognizeDESC');
	}	
	elseif($_REQUEST['flag']=='50'){
		usort($mylist, 'CompareFailASC');
	}elseif($_REQUEST['flag']=='51'){
		usort($mylist, 'CompareFailDESC');
	}	
	elseif($_REQUEST['flag']=='60'){
		usort($mylist, 'CompareOkASC');
	}elseif($_REQUEST['flag']=='61'){
		usort($mylist, 'CompareOkDESC');
	}	
	elseif($_REQUEST['flag']=='70'){
		usort($mylist, 'ComparePersentASC');
	}elseif($_REQUEST['flag']=='71'){
		usort($mylist, 'ComparePersentDESC');
	}	
	
	$winH = 500;
	if(isset($_REQUEST['winH'])) $winH = $_REQUEST['winH'];
	
	$_SESSION['s_recognizes'] = $mylist;
	
	$index = 0;
	foreach ($mylist as $key =>$row){
//$row_re['name'],$row_re['total'],$row_re['unrecognize'],$row_re['recognize_fail'],$row_re['recognize_ok'],$row_re['percent'],$row_re['fromdate'],$row_re['todate'],$row_re['cameraid']
			$index+=1;
			 ?>
			 <tr>
				<td width="6%" align="center"><?=$index?></td>
				<td width="44%" align="center">
					<span onclick="OnSelect('<?=$row[6]?>','<?=$row[7]?>',<?=$row[8]?>,<?=$row[1]?>,<?=$row[2]?>,<?=$row[3]?>,<?=$row[4]?>)" style="cursor:pointer;color:#035a97">
						<?=$row[0]?>
					</span>
				</td>
				<td width="10%" align="center"><?=$row[1]?></td>
				<td width="10%" align="center"><?=$row[2]?></td>
				<td width="10%" align="center"><?=$row[3]?></td>
				<td width="10%" align="center"><?=$row[4]?></td>
				<td width="10%" class="last" align="center" <?php if($row[5] == 100){?>style="color:#00FFB6"<?php }elseif($row[5] < 50 ){?>style="color:#FF3A3A"<?php }?>><?=$row[5]."%"?></td>
			</tr>
			 <?php 
			
				
	}  
	if ($index>0 and $index<$winH/28) {
	 	foreach(range(0,$winH/28-$index) as $i){
	 		?>
	 		<tr>
	 		<td width="6%">&nbsp;</td>
		 	<td width="44%">&nbsp;</td>
		 	<td width="10%">&nbsp;</td>
		 	<td width="10%">&nbsp;</td>
		 	<td width="10%">&nbsp;</td>
		 	<td width="10%">&nbsp;</td>
		 	<td  width="10%"  class="last">&nbsp;</td>
		 	</tr>
	 	<?php }
	}
	  
}
?>

